#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    ifstream ifs("Blocks.in");

    int words = 0;
    ifs >> words;

    vector<set<char>> blocks;

    for(int i = 0; i < 4; ++i){
        string block;
        ifs >> block;

        set<char> coll;
        for(char n : block){
            coll.insert(n);
        }

        blocks.push_back(coll);
    }

    for(int j = 0; j < 6; ++j){
        string word;
        ifs >> word;

        bool ismatch = true;
        
        do{
            for(int i = 0; i < word.size(); ++i){
                if(find(blocks[i].begin(), blocks[i].end(), word[i]) != blocks[i].end()){
                    ismatch = true;
                    break;
                }
            }
        }while(next_permutation(blocks.begin(), blocks.end()));
        if(ismatch){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }    
    return 0;
}
